/*--------------------------------------------------------
Copyright (c) 2010 Apolo Pena

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------*/
package org.flashalchemy.ezlib.ezlog.targets
{
    import org.flashalchemy.ezlib.ezlog.console.EzConsolePanel;
    import mx.core.Application;
    import mx.core.mx_internal;

    use namespace mx_internal;


    /**
     * @inherit
     **/ /**
     * <b>Description:</b> A draggable resizeable debugger console for situations where debugging
     * is needed but the Flex IDE console cannot be used such as a standlone executable.<p/>
     * <b>Usage:</b></br>
     * <pre>
     *      var epct:EzProgramConsoleTarget = new EzProgramConsoleTarget();
     * 		EzLog.addTarget(epct);
     * </pre>
     */
    public class EzProgramConsoleTarget extends EzTraceTarget
    {
        /**
         * The object containing the User Interface
         * @return
         */
        public function get console():EzConsolePanel
        {
            return _console;
        }

        private var _console:EzConsolePanel = new EzConsolePanel();

        /**
         * Constructor sets console height and width, adds the console to
         * the display list of the main application.
         * @param width optional
         * @param height optional
         */
        public function EzProgramConsoleTarget(title:String = null, alpha:Number = 1.0, themeId:String = 'default', x:Number = 16, y:Number = 8, width:Number = 500, height:Number = 200)
        {
            super();
            _console = new EzConsolePanel(title, alpha, themeId);
            _console.width = width;
            _console.height = height;
            _console.x = x;
            _console.y = y;
            _console.alpha = alpha;
            Application.application.addChild(_console);
        }

        //--------------------------------------------------------------------------
        //
        //  Overridden Methods
        //
        //--------------------------------------------------------------------------
        /**
         *  @private
         *  This method outputs the specified message directly to a
         *  <code>org.flashalchemy.ezlib.logging.console.EzConsoleTarget</code> object.
         *  All output will be directed to flashlog.txt by default.
         *
         *  @param message String containing preprocessed log message which may
         *  include time, date, category, etc. based on property settings,
         *  such as <code>includeDate</code>, <code>includeCategory</code>, etc.
         */
        override mx_internal function internalLog(message:String):void
        {
            console.output = message;
        }
    }
}

